import api, {BaseUrl} from '../utils/http.js';
import axios from "axios";

export async function login(data) {
    return api.post('/login', data);
}

export async function userInfo(data) {
    return api.get('/user/info/' + data);
}

export async function getUserList(data) {
    return api.get('/selectUser/page', data);
}

export async function addUser(data) {
    return api.post('/insertUserInfo', data);
}

export async function updateUserInfo(data) {
    return api.put('/updateUserInfo', data);
}

export async function deleteUser(data) {
    return api.delete('/deleteUser/' + data);
}

export async function exportUserList() {
    const file = await axios.get(BaseUrl + '/user/export', {
        responseType: 'blob', // 重要：指定响应类型为 Blob
        headers: {
            'Content-Type': 'application/json;charset=UTF-8',
            'access-token': localStorage.getItem('token')
        }
    });

    // 创建 Blob 对象
    const blob = new Blob([file.data]);

    // 创建链接并触发下载
    const link = document.createElement('a');
    link.href = window.URL.createObjectURL(blob);
    link.download = '员工信息.xlsx'; // 设置下载的文件名
    link.click();

    // 释放 URL 对象
    window.URL.revokeObjectURL(link.href);
}


